<?php if( ! defined('BASEPATH')) exit('No direct script access allowed');
	class can_register extends CI_Controller
	{
		public function __construct()
		{
			parent::__construct();
			$this->load->model('can_register_model');
		}
	
		/* public function index()
		{	
			$this->load->helper('url');
			$this->load->view('template/header');
			$this->load->view('template/menu');
			$this->load->view('can_register');
			$this->load->view('template/footer');

			// create array to get data from index
			$data = array(
				'fname' => $this->input->post('fname'),
				'lname' => $this->input->post('lname'),
				'nickname' => $this->input->post('nickname'),
				'username' => $this->input->post('username'),
				'password' => $this->input->post('password'),
				'email' => $this->input->post('email'),
				'veryfies_code' => $this->input->post('veryfies_code'),
				'status' => $this->input->post('status')
			);
			
			// transferring data to model
			$this->can_register_model->can_insert($data);
			$data['message'] = 'Data Inserted Successfully';

			// loading view
			$this->load->view('can_account');

		} */

		public function can_login()
		{			
			if(($this->session->userdata('user_name')!=""))
			{
				$this->can_account();
			}else{
			
			$data['title'] = 'Login';
			$this->load->helper('url');
			$this->load->view('template/header',$data);
			$this->load->view('template/menu');
			$this->load->view('can_login',$data);
			$this->load->view('template/footer',$data);
			}
		}
		
		public function login()
		{
			// login
			if(isset($_POST['user_name']))
			{
				// fetch user from database
				$can_log = $this->db->get_where('candidate',array('user_name'=>$_POST['user_name'],'password'=>md5($_POST['password']),'status'=>1))->result();
				
				if(!empty($can_log))
				{
					echo "LoggedIn";
					foreach($can_log as $rows)
						{
							// add all data to session
							$newdata = array(
								'user_id' => $rows->id,
								'user_name' => $rows->user_name,
								'email' => $rows->email,
								'logged_in' => true
							);
						}
						$this->session->set_userdata($newdata);
						return true;
						
				}else{
					echo "No";
					return false;
				}
				
			}
			
		}

		public function can_account()
		{
			if(($this->session->userdata('user_name')!=""))
			{
				$data['title'] = 'Register Account';
				$this->load->helper('url');
				$this->load->view('template/header',$data);
				$this->load->view('can_account_header',$data);
				$this->load->view('can_adminjob',$data);
				$this->load->view('can_account_footer',$data);
			}else{
				$this->can_login();
			}
			
		}
		// view account profile
		public function account()
		{
			$email = $this->session->userdata('email');
			if($email=="")
			{
				$this->can_account();
			}else{
				$this->load->helper('url');
				$this->load->view('template/header');
				$this->load->view('can_account_header');
				$data['single_can'] = $this->can_register_model->get_resume($email);
				$this->load->view('account',$data);
				$this->load->view('can_account_footer');
			}
		}
		
		public function can_record()
		{
			if(($this->session->userdata('user_name')!=""))
			{
				$data['title'] = 'Register Account';
				$this->load->helper('url');
				$this->load->view('template/header');
				$this->load->view('can_account_header');
				$this->load->view('can_record',$data);
				$this->load->view('can_account_footer');
			}else{
				$this->can_login();
			}
			
		}
		
		// view cv
/* 		public function resume()
		{
			$email = $this->session->userdata('email');
			if($email=="")
			{
				$this->can_account();
			}else{
				$this->load->helper('url');
				$this->load->view('template/header');
				$this->load->view('can_account_header');
				$data['single_can'] = $this->can_register_model->get_resume($email);
				$this->load->view('resume',$data);
				$this->load->view('can_account_footer');
			}
		} */
		
		public function resume()
		{
			$email = $this->session->userdata('email');
			if($email=="")
			{
				$this->can_account();
			}else{
				$this->load->helper('url');
				$this->load->view('template/header');
				$this->load->view('can_account_header');
				//$data['single_can'] = $this->can_register_model->get_resume($email);
				$this->load->view('pro_menu');
				$this->load->view('pro_panel_r');
				$this->load->view('can_account_footer');
			}
		}
		
		public function re_about()
		{
			$this->load->helper('url');
				$this->load->view('template/header');
				$this->load->view('can_account_header');
				//$data['single_can'] = $this->can_register_model->get_resume($email);
				$this->load->view('pro_menu');
				$this->load->view('re_about');
				$this->load->view('can_account_footer');
		}
		
		public function re_experience()
		{
			$this->load->helper('url');
				$this->load->view('template/header');
				$this->load->view('can_account_header');
				//$data['single_can'] = $this->can_register_model->get_resume($email);
				$this->load->view('pro_menu');
				$this->load->view('re_experience');
				$this->load->view('can_account_footer');
		}
		
		public function re_education()
		{
			$this->load->helper('url');
				$this->load->view('template/header');
				$this->load->view('can_account_header');
				//$data['single_can'] = $this->can_register_model->get_resume($email);
				$this->load->view('pro_menu');
				$this->load->view('re_education');
				$this->load->view('can_account_footer');
		}
		
		public function re_expectation()
		{
			$this->load->helper('url');
				$this->load->view('template/header');
				$this->load->view('can_account_header');
				//$data['single_can'] = $this->can_register_model->get_resume($email);
				$this->load->view('pro_menu');
				$this->load->view('re_expectation');
				$this->load->view('can_account_footer');
		}
		
		public function re_skill()
		{
			$this->load->helper('url');
				$this->load->view('template/header');
				$this->load->view('can_account_header');
				//$data['single_can'] = $this->can_register_model->get_resume($email);
				$this->load->view('pro_menu');
				$this->load->view('re_skill');
				$this->load->view('can_account_footer');
		}
		
		public function auto_match() 
		{
			$email = $this->session->userdata('email');
			if($email == "")
			{
				$this->can_account();
			}else{
				$this->load->helper('url');
				$this->load->view('template/header');
				$this->load->view('can_account_header');
				$this->load->view('can_automatch');
				$this->load->view('can_account_footer');
			}
		}
		
		public function experience() 
		{
			$email = $this->session->userdata('email');
			if($email == "")
			{
				$this->can_account();
			}else{
				$this->load->helper('url');
				$this->load->view('template/header');
				$this->load->view('can_account_header');
				$this->load->view('can_experience');
				$this->load->view('can_account_footer');
			}
		}
		
/* 		// get resume
		public function get_resume()
		{
			$email = $this->session->userdata('email');
			$result = $this->can_register_model->get_resume($email);
			if($result)
			{
				return true;
			}else{
				return false;
			}
		} */
		
		public function can_adminjob()
		{
			if(($this->session->userdata('user_name')==""))
			{
				$this->can_account();
			}else{
				$this->load->helper('url');
				$this->load->view('template/header');
				$this->load->view('can_account_header');
				$this->load->view('can_adminjob');
				$this->load->view('can_account_footer');
			}
			
		}
		public function captcha()
		{
			$this->load->view('captcha');
		}
		
		// veryfies captcha
		public function captcha_veryfies()
		{
			$this->load->view('captcha_veryfies');
		}
		
		// logout
		public function logout()
		{
			$newdata = array(
				'user_id' => '',
				'user_name' => '',
				'email' => '',
				'logged_in' => false
			);
			$this->session->unset_userdata($newdata);
			$this->session->sess_destroy();
			$this->can_login();
		}
		
		// add candidate
		public function can_add()
		{
			$data['title'] = 'Add Account';
			$this->load->helper('url');
			$this->load->view('template/header',$data);
			$this->load->view('template/menu',$data);
			$this->load->view('can_add',$data);
			$this->load->view('template/footer',$data);
		}
		// save data to database table name candidate
		public function can_save()
		{
			$this->can_register_model->can_save();
			$this->after_logout();
		}
		// update candidate
		public function can_update()
		{
			$id = $this->input->post('id');
			$data = array(
				'first_name' => $this->input->post('first_name'),
				'last_name' => $this->input->post('last_name'),
				'nick_name' => $this->input->post('nick_name'),
				'email' => $this->input->post('email')
			);
			$result = $this->can_register_model->can_update($id,$data);
			if($result)
			{
				echo "Yes";
				$this->account();
			}else{
				echo "No";
			}
			
		}
		
		// after logout
		public function after_logout()
		{
			$data['title'] = 'Logged Out';
			$this->load->helper('url');
			$this->load->view('template/header',$data);
			$this->load->view('template/menu');
			$this->load->view('can_login',$data);
			$this->load->view('template/footer',$data);
		}
		
		// check user
		public function check_user()
	{
		$usr=$this->input->post('name');
        $result=$this->can_register_model->check_user_exist($usr);
        if($result)
        {
			echo "false";
			
        }
        else{
			
			echo "true";
        }
	}
		

	}


?>